{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "66a3faed",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-10-25\n",
    "* 课程：Python语言\n",
    "* week06\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "36799f83",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This minute seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "# 项目一：判断当前时钟的分钟是否为奇数\n",
    "from datetime import datetime\n",
    "\n",
    "# odds是一个变量，存放奇数数组（列表）1-59 特指分钟的奇数数值\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "# 使用了datetime模块中的datetime方法，用today()获取当前的时钟（年月日时分秒），选择出分钟minute作为我们的right_this_minute\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "# 判断当前时钟分钟是否在odds这个变量数组里面\n",
    "if right_this_minute in odds:\n",
    "    # 1. 条件一：在odds里面，为奇数分钟时间\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    # 2. 条件二：不在odds，为偶数分钟时间\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee14e956",
   "metadata": {},
   "source": [
    "# 2. 项目二：详解\n",
    "\n",
    "> 1. 使用for循环迭代项目一，让执行次数为5次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7dd121ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.759792949497523"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random 随机数的练习，random和randint两个方法\n",
    "import random\n",
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "05989026",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "27\n",
      "4\n",
      "2\n",
      "60\n",
      "50\n",
      "27\n"
     ]
    }
   ],
   "source": [
    "for i in range(7):\n",
    "    print(int(random.random()*100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "6f36326f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(0,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "ecf1f1f4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前时钟为偶数秒钟，为30秒，时间即将静止2秒\n",
      "当前时钟为偶数秒钟，为32秒，时间即将静止4秒\n",
      "当前时钟为偶数秒钟，为36秒，时间即将静止2秒\n",
      "当前时钟为偶数秒钟，为38秒，时间即将静止2秒\n",
      "当前时钟为偶数秒钟，为40秒，时间即将静止5秒\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,\n",
    "        19,21,23,25,27,29,31,\n",
    "        33,35,37,39,41,43,45,\n",
    "        47,49,51,53,55,57,59]\n",
    "\n",
    "# for + range 可以决定执行循环的次数，如以下for循环执行了5次\n",
    "for i in range(5):\n",
    "    # 等待时间是一个1-5之间随机的整数秒钟\n",
    "    wait_time = random.randint(1,5)\n",
    "\n",
    "    #\n",
    "    right_this_second = datetime.today().second\n",
    "    #\n",
    "    if right_this_second in odds:\n",
    "        print(\"当前时钟为奇数秒钟，为%s秒，时间即将静止%s秒\"%(right_this_second,wait_time))\n",
    "    else:\n",
    "        print(\"当前时钟为偶数秒钟，为%s秒，时间即将静止%s秒\"%(right_this_second,wait_time))\n",
    "    # sleep：程序停止时间（秒）\n",
    "    time.sleep(wait_time)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d241283",
   "metadata": {},
   "source": [
    "# 3.项目三：啤酒颂"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "a1042e61",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 bottles of beer on the wall.\n",
      "99 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "98 bottles of beer on the wall.\n",
      "\n",
      "98 bottles of beer on the wall.\n",
      "98 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "97 bottles of beer on the wall.\n",
      "\n",
      "97 bottles of beer on the wall.\n",
      "97 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "96 bottles of beer on the wall.\n",
      "\n",
      "96 bottles of beer on the wall.\n",
      "96 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "95 bottles of beer on the wall.\n",
      "\n",
      "95 bottles of beer on the wall.\n",
      "95 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "94 bottles of beer on the wall.\n",
      "\n",
      "94 bottles of beer on the wall.\n",
      "94 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "93 bottles of beer on the wall.\n",
      "\n",
      "93 bottles of beer on the wall.\n",
      "93 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "92 bottles of beer on the wall.\n",
      "\n",
      "92 bottles of beer on the wall.\n",
      "92 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "91 bottles of beer on the wall.\n",
      "\n",
      "91 bottles of beer on the wall.\n",
      "91 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "90 bottles of beer on the wall.\n",
      "\n",
      "90 bottles of beer on the wall.\n",
      "90 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "89 bottles of beer on the wall.\n",
      "\n",
      "89 bottles of beer on the wall.\n",
      "89 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "88 bottles of beer on the wall.\n",
      "\n",
      "88 bottles of beer on the wall.\n",
      "88 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "87 bottles of beer on the wall.\n",
      "\n",
      "87 bottles of beer on the wall.\n",
      "87 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "86 bottles of beer on the wall.\n",
      "\n",
      "86 bottles of beer on the wall.\n",
      "86 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "85 bottles of beer on the wall.\n",
      "\n",
      "85 bottles of beer on the wall.\n",
      "85 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "84 bottles of beer on the wall.\n",
      "\n",
      "84 bottles of beer on the wall.\n",
      "84 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "83 bottles of beer on the wall.\n",
      "\n",
      "83 bottles of beer on the wall.\n",
      "83 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "82 bottles of beer on the wall.\n",
      "\n",
      "82 bottles of beer on the wall.\n",
      "82 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "81 bottles of beer on the wall.\n",
      "\n",
      "81 bottles of beer on the wall.\n",
      "81 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "80 bottles of beer on the wall.\n",
      "\n",
      "80 bottles of beer on the wall.\n",
      "80 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "79 bottles of beer on the wall.\n",
      "\n",
      "79 bottles of beer on the wall.\n",
      "79 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "78 bottles of beer on the wall.\n",
      "\n",
      "78 bottles of beer on the wall.\n",
      "78 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "77 bottles of beer on the wall.\n",
      "\n",
      "77 bottles of beer on the wall.\n",
      "77 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "76 bottles of beer on the wall.\n",
      "\n",
      "76 bottles of beer on the wall.\n",
      "76 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "75 bottles of beer on the wall.\n",
      "\n",
      "75 bottles of beer on the wall.\n",
      "75 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "74 bottles of beer on the wall.\n",
      "\n",
      "74 bottles of beer on the wall.\n",
      "74 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "73 bottles of beer on the wall.\n",
      "\n",
      "73 bottles of beer on the wall.\n",
      "73 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "72 bottles of beer on the wall.\n",
      "\n",
      "72 bottles of beer on the wall.\n",
      "72 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "71 bottles of beer on the wall.\n",
      "\n",
      "71 bottles of beer on the wall.\n",
      "71 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "70 bottles of beer on the wall.\n",
      "\n",
      "70 bottles of beer on the wall.\n",
      "70 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "69 bottles of beer on the wall.\n",
      "\n",
      "69 bottles of beer on the wall.\n",
      "69 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "68 bottles of beer on the wall.\n",
      "\n",
      "68 bottles of beer on the wall.\n",
      "68 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "67 bottles of beer on the wall.\n",
      "\n",
      "67 bottles of beer on the wall.\n",
      "67 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "66 bottles of beer on the wall.\n",
      "\n",
      "66 bottles of beer on the wall.\n",
      "66 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "65 bottles of beer on the wall.\n",
      "\n",
      "65 bottles of beer on the wall.\n",
      "65 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "64 bottles of beer on the wall.\n",
      "\n",
      "64 bottles of beer on the wall.\n",
      "64 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "63 bottles of beer on the wall.\n",
      "\n",
      "63 bottles of beer on the wall.\n",
      "63 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "62 bottles of beer on the wall.\n",
      "\n",
      "62 bottles of beer on the wall.\n",
      "62 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "61 bottles of beer on the wall.\n",
      "\n",
      "61 bottles of beer on the wall.\n",
      "61 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "60 bottles of beer on the wall.\n",
      "\n",
      "60 bottles of beer on the wall.\n",
      "60 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "59 bottles of beer on the wall.\n",
      "\n",
      "59 bottles of beer on the wall.\n",
      "59 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "58 bottles of beer on the wall.\n",
      "\n",
      "58 bottles of beer on the wall.\n",
      "58 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "57 bottles of beer on the wall.\n",
      "\n",
      "57 bottles of beer on the wall.\n",
      "57 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "56 bottles of beer on the wall.\n",
      "\n",
      "56 bottles of beer on the wall.\n",
      "56 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "55 bottles of beer on the wall.\n",
      "\n",
      "55 bottles of beer on the wall.\n",
      "55 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "54 bottles of beer on the wall.\n",
      "\n",
      "54 bottles of beer on the wall.\n",
      "54 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "53 bottles of beer on the wall.\n",
      "\n",
      "53 bottles of beer on the wall.\n",
      "53 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "52 bottles of beer on the wall.\n",
      "\n",
      "52 bottles of beer on the wall.\n",
      "52 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "51 bottles of beer on the wall.\n",
      "\n",
      "51 bottles of beer on the wall.\n",
      "51 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "50 bottles of beer on the wall.\n",
      "\n",
      "50 bottles of beer on the wall.\n",
      "50 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "49 bottles of beer on the wall.\n",
      "\n",
      "49 bottles of beer on the wall.\n",
      "49 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "48 bottles of beer on the wall.\n",
      "\n",
      "48 bottles of beer on the wall.\n",
      "48 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "47 bottles of beer on the wall.\n",
      "\n",
      "47 bottles of beer on the wall.\n",
      "47 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "46 bottles of beer on the wall.\n",
      "\n",
      "46 bottles of beer on the wall.\n",
      "46 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "45 bottles of beer on the wall.\n",
      "\n",
      "45 bottles of beer on the wall.\n",
      "45 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "44 bottles of beer on the wall.\n",
      "\n",
      "44 bottles of beer on the wall.\n",
      "44 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "43 bottles of beer on the wall.\n",
      "\n",
      "43 bottles of beer on the wall.\n",
      "43 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "42 bottles of beer on the wall.\n",
      "\n",
      "42 bottles of beer on the wall.\n",
      "42 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "41 bottles of beer on the wall.\n",
      "\n",
      "41 bottles of beer on the wall.\n",
      "41 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "40 bottles of beer on the wall.\n",
      "\n",
      "40 bottles of beer on the wall.\n",
      "40 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "39 bottles of beer on the wall.\n",
      "\n",
      "39 bottles of beer on the wall.\n",
      "39 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "38 bottles of beer on the wall.\n",
      "\n",
      "38 bottles of beer on the wall.\n",
      "38 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "37 bottles of beer on the wall.\n",
      "\n",
      "37 bottles of beer on the wall.\n",
      "37 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "36 bottles of beer on the wall.\n",
      "\n",
      "36 bottles of beer on the wall.\n",
      "36 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "35 bottles of beer on the wall.\n",
      "\n",
      "35 bottles of beer on the wall.\n",
      "35 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "34 bottles of beer on the wall.\n",
      "\n",
      "34 bottles of beer on the wall.\n",
      "34 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "33 bottles of beer on the wall.\n",
      "\n",
      "33 bottles of beer on the wall.\n",
      "33 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "32 bottles of beer on the wall.\n",
      "\n",
      "32 bottles of beer on the wall.\n",
      "32 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "31 bottles of beer on the wall.\n",
      "\n",
      "31 bottles of beer on the wall.\n",
      "31 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "30 bottles of beer on the wall.\n",
      "\n",
      "30 bottles of beer on the wall.\n",
      "30 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "29 bottles of beer on the wall.\n",
      "\n",
      "29 bottles of beer on the wall.\n",
      "29 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "28 bottles of beer on the wall.\n",
      "\n",
      "28 bottles of beer on the wall.\n",
      "28 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "27 bottles of beer on the wall.\n",
      "\n",
      "27 bottles of beer on the wall.\n",
      "27 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "26 bottles of beer on the wall.\n",
      "\n",
      "26 bottles of beer on the wall.\n",
      "26 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "25 bottles of beer on the wall.\n",
      "\n",
      "25 bottles of beer on the wall.\n",
      "25 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "24 bottles of beer on the wall.\n",
      "\n",
      "24 bottles of beer on the wall.\n",
      "24 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "23 bottles of beer on the wall.\n",
      "\n",
      "23 bottles of beer on the wall.\n",
      "23 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "22 bottles of beer on the wall.\n",
      "\n",
      "22 bottles of beer on the wall.\n",
      "22 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "21 bottles of beer on the wall.\n",
      "\n",
      "21 bottles of beer on the wall.\n",
      "21 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "20 bottles of beer on the wall.\n",
      "\n",
      "20 bottles of beer on the wall.\n",
      "20 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "19 bottles of beer on the wall.\n",
      "\n",
      "19 bottles of beer on the wall.\n",
      "19 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "18 bottles of beer on the wall.\n",
      "\n",
      "18 bottles of beer on the wall.\n",
      "18 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "17 bottles of beer on the wall.\n",
      "\n",
      "17 bottles of beer on the wall.\n",
      "17 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "16 bottles of beer on the wall.\n",
      "\n",
      "16 bottles of beer on the wall.\n",
      "16 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "15 bottles of beer on the wall.\n",
      "\n",
      "15 bottles of beer on the wall.\n",
      "15 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "14 bottles of beer on the wall.\n",
      "\n",
      "14 bottles of beer on the wall.\n",
      "14 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "13 bottles of beer on the wall.\n",
      "\n",
      "13 bottles of beer on the wall.\n",
      "13 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "12 bottles of beer on the wall.\n",
      "\n",
      "12 bottles of beer on the wall.\n",
      "12 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "11 bottles of beer on the wall.\n",
      "\n",
      "11 bottles of beer on the wall.\n",
      "11 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "10 bottles of beer on the wall.\n",
      "\n",
      "10 bottles of beer on the wall.\n",
      "10 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "9 bottles of beer on the wall.\n",
      "\n",
      "9 bottles of beer on the wall.\n",
      "9 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "8 bottles of beer on the wall.\n",
      "\n",
      "8 bottles of beer on the wall.\n",
      "8 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "7 bottles of beer on the wall.\n",
      "\n",
      "7 bottles of beer on the wall.\n",
      "7 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "6 bottles of beer on the wall.\n",
      "\n",
      "6 bottles of beer on the wall.\n",
      "6 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "5 bottles of beer on the wall.\n",
      "\n",
      "5 bottles of beer on the wall.\n",
      "5 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "4 bottles of beer on the wall.\n",
      "\n",
      "4 bottles of beer on the wall.\n",
      "4 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "3 bottles of beer on the wall.\n",
      "\n",
      "3 bottles of beer on the wall.\n",
      "3 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "2 bottles of beer on the wall.\n",
      "\n",
      "2 bottles of beer on the wall.\n",
      "2 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "1 bottle of beer on the wall.\n",
      "\n",
      "1 bottle of beer on the wall.\n",
      "1 bottle of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "No more bottles of beer on the wall.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 啤酒墙，每一次拿走一瓶啤酒，直到全部拿完，就没有了\n",
    "\n",
    "word = \"bottles\"\n",
    "# range决定起始的啤酒数量，当前为99;range决定每一次拿多少瓶走，当前为1\n",
    "for beer_num in range(99, 0, -1):\n",
    "    print(beer_num, word, \"of beer on the wall.\")\n",
    "    print(beer_num, word, \"of beer.\")\n",
    "    print(\"Take one down.\")\n",
    "    print(\"Pass it around.\")\n",
    "    # 判断啤酒数量是否为 1\n",
    "    if beer_num == 1:\n",
    "        # 如果beer_num为1 new_num 已经为0了，则没有了 \n",
    "        print(\"No more bottles of beer on the wall.\")\n",
    "        \n",
    "    else:\n",
    "        # 当beer_num为2的时候 \n",
    "        new_num = beer_num - 1\n",
    "        # 当 new_num为1的时候\n",
    "        if new_num == 1:\n",
    "            # 把bottles 改为单数 bottle\n",
    "            word = \"bottle\"\n",
    "        print(new_num, word, \"of beer on the wall.\")\n",
    "    print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a962e21f",
   "metadata": {},
   "source": [
    "# 4. While循环\n",
    "\n",
    "* while True\n",
    "> 1. while 一般和True一起使用，表示无限循环\n",
    "> 2. while True 一般在程序过程内部可以执行一个条件，当条件成立时结束此循环\n",
    "> 3. 结束循环：break"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9af0d90e",
   "metadata": {},
   "source": [
    "while True:\n",
    "    print(\"你是风儿我是沙，寻寻觅觅到天涯...\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "c6c15362",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙，寻寻觅觅到天涯... 1\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 2\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 3\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 4\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 5\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 6\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 7\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 8\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 9\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 10\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 11\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 12\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 13\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 14\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 15\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 16\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 17\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 18\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 19\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 20\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 21\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 22\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 23\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 24\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 25\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 26\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 27\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 28\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 29\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 30\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 31\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 32\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 33\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 34\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 35\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 36\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 37\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 38\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 39\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 40\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 41\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 42\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 43\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 44\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 45\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 46\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 47\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 48\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 49\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 50\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 51\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 52\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 53\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 54\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 55\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 56\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 57\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 58\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 59\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 60\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 61\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 62\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 63\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 64\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 65\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 66\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 67\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 68\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 69\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 70\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 71\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 72\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 73\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 74\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 75\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 76\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 77\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 78\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 79\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 80\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 81\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 82\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 83\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 84\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 85\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 86\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 87\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 88\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 89\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 90\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 91\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 92\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 93\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 94\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 95\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 96\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 97\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 98\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 99\n",
      "你是风儿我是沙，寻寻觅觅到天涯... 100\n"
     ]
    }
   ],
   "source": [
    "count = 0  # 计数器\n",
    "while True:\n",
    "    count = count + 1\n",
    "    print(\"你是风儿我是沙，寻寻觅觅到天涯...\",count)\n",
    "    if count == 100:\n",
    "        break # 终止循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05c3c8ed",
   "metadata": {},
   "source": [
    "## 2. 猜数字小游戏\n",
    "\n",
    "> 1. 给一个隐藏的卡片（背后有一个数字1-100）\n",
    "> 2. 邀请一位小伙伴来猜数字（指定5次机会）\n",
    "> 3. 一共有两种可能：\n",
    ">> 1. 第一种：猜对了，break，game over successed！\n",
    ">> 2. 第二种：猜错了（多一层判断，尝试次数是否够5次）\n",
    ">>> 1. 如果比隐藏卡片的数值大，我们将给一些提示，例如往小一点猜\n",
    ">>> 1. 如果比隐藏卡片的数值小，我们将给一些提示，例如往大一点猜\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "eceac60d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "出题人请出你心中的数字：········\n",
      "请输入你认为的数字：50\n",
      "你真棒！猜对啦，游戏结束~\n"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "\n",
    "hide_card = int(getpass.getpass(\"出题人请出你心中的数字：\"))\n",
    "\n",
    "while True:\n",
    "    game_users = int(input(\"请输入你认为的数字：\"))\n",
    "    if hide_card == game_users:\n",
    "        print(\"你真棒！猜对啦，游戏结束~\")\n",
    "        break\n",
    "    else:\n",
    "        if game_users > hide_card:\n",
    "            print(\"你可以往小了猜~加油~\")\n",
    "        else:\n",
    "            print(\"你可以试着往大一点猜，加油~\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2dae80f9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
